﻿#region Using directives
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using gpsMe.Utils;
#endregion

namespace gpsMe.Properties
{
    /// <summary>
    /// Properties of gpsMe
    /// </summary>
    public class gpsMeProperties
    {
        #region Instance
        /// <summary>
        /// Current language instance
        /// </summary>
        public static gpsMeProperties Instance { get; private set; }
        #endregion

        #region Main properties
        /// <summary>
        /// Current version of the gpsMe Xml language file format
        /// </summary>
        public const string CURRENT_GPSMEPROPERTIES_VERSION = "0.1";

        /// <summary>
        /// Version of this gpsMe build
        /// </summary>
        public const string GPSME_CURRENT_VERSION = "0.3";

        /// <summary>
        /// Title of the software
        /// </summary>
        public const string GPSME_TITLE = "gpsMe v" + GPSME_CURRENT_VERSION;

        /// <summary>
        /// gpsMe client width
        /// </summary>
        public const int GPSME_DEFAULT_WIDTH = 480;

        /// <summary>
        /// gpsMe client height
        /// </summary>
        public const int GPSME_DEFAULT_HEIGHT = 640;
        #endregion

        #region File Properties
        /// <summary>
        /// Current version of the properties.xml file
        /// </summary>
        public string PropertiesVersion { get; private set; }
        #endregion

        #region Constructor
        /// <summary>
        /// Constructor of gpsMeProperties
        /// </summary>
        /// <param name="p_sPropertiesXmlPath">path of the gpsMe xml properties file</param>
        public gpsMeProperties(string p_sPropertiesXmlPath)
        {
            Instance = this;
            this.LoadFromXml(p_sPropertiesXmlPath);
        }
        #endregion

        #region Xml loading
        /// <summary>
        /// Loads the current properties from an Xml File
        /// </summary>
        /// <param name="p_sLanguageXmlPath">path of the gpsMe xml properties file</param>
        private void LoadFromXml(string p_sPropertiesXmlPath)
        {
            // Create an instance of XmlTextReader and call Read method to read the file
            XmlTextReader oXmlTextReader = new XmlTextReader(p_sPropertiesXmlPath);
            oXmlTextReader.Read();
            // If the node has value
            while (oXmlTextReader.Read())
            {
                #region gpsMeProperties Version
                    if (oXmlTextReader.LocalName == "gpsMePropertiesVersion")
                        this.PropertiesVersion = gpsMeUtils.LoadValueFromXml(ref oXmlTextReader);
                #endregion
            }
        }
        #endregion
    }
}
